package com.bigevent.bigevent.exception;

import com.bigevent.bigevent.entity.Result;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author yangxudong
 * @description: 异常处理器
 * @date 2024/2/3 13:27
 */
@ControllerAdvice
@ResponseBody
public class GlobalExceptionHandler {
    /**
     * Handles exceptions of type Exception
     * @param e the exception to handle
     * @return a Result object containing the error message
     */
    @ExceptionHandler(Exception.class)
    public Result<String> ExceptionHandler(Exception e) {
        // Return a Result object with the error message from the exception
        e.printStackTrace();
        return Result.error(StringUtils.hasLength(e.getMessage())?e.getMessage():"操作失败");
    }
}
